//
//  CZButton+Extension.swift
//  Weibo24
//
//  Created by apple on 16/3/8.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

/*
    扩展的构造方法,一般都是 convenience便利构造方法
    1. 有可能返回一个 为nil的实例
    2. convenience 关键字
    3. 便利构造函数是唯一一个需要调用,其他的构造函数的
*/
// 类似于OC里的 Category

extension UIButton {


    convenience init(title: String?,image: String?,selectedImage: String?,tag: Int,target:AnyObject?,action: Selector){
    
        self.init()
        
        self.setTitle(title, forState: UIControlState.Normal)
        if let Oimage = image{
        
            self.setBackgroundImage(UIImage(named: Oimage), forState: UIControlState.Normal)
            
        }
        
        if let OSelectImage = selectedImage {
            
            self.setBackgroundImage(UIImage(named: OSelectImage), forState: UIControlState.Selected)
        }
        
        self.tag = tag
        
        self.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
}

